Add route reading code.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 21 Dec 2003 17:48:42 +0000 (17:48 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 21 Dec 2003 17:48:42 +0000 (17:48 +0000)
gpsbabel/garmin.c

index 1b7efb6a9d87f24cdf8472ca58424a8abd71cc17..2e6612a92c474a3768ed3e9a9fabdcdc83f78555 100644 (file)
@@ -143,6 +143,57 @@ track_read(void)
        xfree(array);
 }
 
+static
+void
+route_read(void)
+{
+       int32 nroutepts;
+       int i;
+       GPS_PWay *array;
+
+       nroutepts = GPS_Command_Get_Route(portname, &array);
+
+       fprintf(stderr, "Routes %d\n", nroutepts);
+#if 1
+       for (i = 0; i < nroutepts; i++) {
+               route_head *rte_head;
+               waypoint * wpt_tmp;
+
+               if (array[i]->isrte) {
+                       char *csrc = NULL;
+                       /* What a horrible API has libjeeps for making this
+                        * my problem.
+                        */
+                       switch (array[i]->rte_prot) {
+                               case 201: csrc = array[i]->rte_cmnt; break;
+                               case 202: csrc = array[i]->rte_ident; break;
+                               default: break;
+                       }
+               rte_head = route_head_alloc();
+               route_add_head(rte_head);
+               if (csrc) {
+                       rte_head->rte_name = xstrdup(csrc);
+               }
+               ;
+               
+               } else { 
+                       if (array[i]->islink)  {
+                               continue; 
+                       } else {
+                               wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1);
+                               wpt_tmp->latitude = array[i]->lat;
+                               wpt_tmp->longitude = array[i]->lon;
+                               wpt_tmp->shortname = array[i]->ident;
+                               route_add_wpt(rte_head, wpt_tmp);
+                       }
+               }
+       }
+#else
+       GPS_Fmt_Print_Route(array, nroutepts, stderr);
+#endif
+
+}
+
 static void
 data_read(void)
 {
@@ -153,8 +204,12 @@ data_read(void)
                case wptdata:
                        waypt_read();
                        break;
+               case rtedata:
+                       route_read();
+                       break;
                default:
-                       fatal(MYNAME ": Routes are not yet supported\n");
+                       fatal(MYNAME ": Unknown objective %d.\n", 
+                                       global_opts.objective);
        }
 }